#!/bin/bash

echo "拉取 wurstmeister/zookeeper docker镜像..."
docker pull wurstmeister/zookeeper
 
while true; do
    read -p "请输入zookeeper对外映射端口 (1-65535): " zookeeper_port
    if [[ ! $zookeeper_port =~ ^[0-9]+$ ]] || [ $zookeeper_port -le 0 ] || [ $zookeeper_port -gt 65535 ]; then
        echo "端口号无效。请输入一个在1到65535之间的数字."
    else
        break
    fi
done

# 运行Zookeeper容器
echo "Starting Zookeeper container..."
docker run -d \
           --name zookeeper \
           -p $zookeeper_port:2181 \
           -e TZ="Asia/Shanghai" \
           --restart always \
           wurstmeister/zookeeper

echo "Zookeeper容器已启动."